package zelix.hack.hacks;

import java.lang.reflect.Field;

import zelix.hack.Hack;
import zelix.hack.HackCategory;
import zelix.managers.CommandManager;
import zelix.utils.system.Connection;
import net.minecraft.network.play.client.CPacketChatMessage;
import net.minecraftforge.fml.relauncher.ReflectionHelper;

public class CommandGetter extends Hack {
	public CommandGetter() {
		super("CommandGetter", HackCategory.ANOTHER);
		setToggled(true);
		setShow(false);
	}

	@Override
	public boolean onPacket(Object packet, Connection.Side side) {
		boolean send=true;
		if (side == Connection.Side.OUT) {
			if (packet instanceof CPacketChatMessage) {

				Field field = ReflectionHelper.findField(CPacketChatMessage.class,
						new String[] { "message", "field_149440_a" });

				try {

					if (!field.isAccessible()) {
						field.setAccessible(true);
					}

					if (packet instanceof CPacketChatMessage) {
						CPacketChatMessage p = (CPacketChatMessage) packet;
						if (p.getMessage().subSequence(0, 1).equals(".")) {
							send=false;
							CommandManager.getInstance().runCommands(p.getMessage());
							return send;
						}else {
							send=true;
						}
					}

				} catch (Exception e) { // e.printStackTrace();

				}

			}
		}
		return send;
	}

}
